Working with OLE objects

Setting the location of an OLE object

This example demonstrates how you can set the location of an OLE object at Runtime using the SetOleLocation command. The example takes three different OLE objects:

It cycles through them so the RDC prints a different object each time it formats the Details section.

Option Explicit
Private Sub Report_Initialize()
    Database.Tables(1).Location = App.Path + "\Author.mdb"
End Sub
Private Sub SectionDetails_Format(ByVal pFormattingInfo As Object)

Object to hold the bitmap:

Dim bmpHold As StdPicture
    Dim iModNum As Integer

Calculate an integer to pass in as the object name.

    iModNum = cRecNum.Value Mod 3 + 1

Take an action based on the integer passed in.

    Select Case iModNum

The bitmap object:

    Case 1

Set the variable to a bitmap.

Set bmpHold = LoadPicture(App.Path & res\SampleBitmap1.bmp")

Set the height and width of the Report object equal to the actual values for the bitmap - the StdPicture object defaults to HiMetric, the Report uses twips.

Set the bitmap on the Report equal to the variable.

Set cOLEObj.FormattedPicture = bmpHold

Convert from HiMetric to twips.

cOLEObj.Height = bmpHold.Height * 567 / 1000 cOLEObj.Width = bmpHold.Width * 567 / 1000

The Excel Worksheet object:

              Case 2
        cOLEObj.SetOleLocation App.Path & "\res\SampleExcel1.xls"
        cOLEObj.Height = 1800
        cOLEObj.Width = 5791

The Word Document object:

Case 3
        cOLEObj.SetOleLocation App.Path & "\res\SampleWord1.doc"
        cOLEObj.Height = 322
        cOLEObj.Width = 8641
    End Select
End Sub


Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com